﻿using Castle.DynamicProxy;
using CNKI.TPI.Web.Base;
using CNKI.TPI.Web.Search.IBLL;
using CNKI.TPI.Web.Search.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.SessionState;

namespace CNKI.TPI.Web.UI.Controllers.Search
{
    [SessionState(SessionStateBehavior.ReadOnly)]
    public class SimilarDocController : BaseController
    {
        INaviService naviService = null;
        ISearchService searchService = null;
        //
        // GET: /SimilarDoc/

        public SimilarDocController(INaviService naviService, ISearchService searchService)
        {
            this.naviService = generator.CreateInterfaceProxyWithTarget<INaviService>(naviService, new IInterceptor[] { new LogInterceptor() });
            this.searchService = generator.CreateInterfaceProxyWithTarget<ISearchService>(searchService, new IInterceptor[] { new LogInterceptor() });
        }
     
        public ActionResult PicList(int dbId, int recordId, string similarWord,string type, string dbCode)
        {
            //if (String.IsNullOrEmpty(similarWord))
            //{
            //    return new ContentResult();
            //}
            //IList<SYS_CMS_DATABASE> list = searchService.GetSimilarList(dbCode);
            //Dictionary<string, DataTable> dicList = new Dictionary<string, DataTable>();
            //List<SYS_CMS_DATABASE> listResult = new List<SYS_CMS_DATABASE>();
            //foreach (SYS_CMS_DATABASE db in list)
            //{
            //    DataSet ds = null;
            //    if (db.SysID == dbId)
            //    {
            //        ds = searchService.SingleSearch(db.SysID, db.DatabaseName, new List<SearchQuery> { new SearchQuery("SYS_FLD_VSM", similarWord), new SearchQuery("SYS_FLD_SYSID", recordId.ToString(), ConditionType.Ne, SearchMatchType.And) }, 0, null, null, null, 1, 4);
            //    }
            //    else
            //    {
            //        ds = searchService.SingleSearch(db.SysID, db.DatabaseName, new List<SearchQuery> { new SearchQuery("SYS_FLD_VSM", similarWord) }, 0, null, null, null, 1, 4);
            //    }
            //    if (ds != null && ds.Tables[0].Rows.Count > 0)
            //    {
            //        listResult.Add(db);
            //        dicList.Add(db.DatabaseCode, ds.Tables[0]);
            //    }
            //}
            //ViewBag.Type = type;
            //ViewBag.PicDbList = listResult;
            //ViewBag.PicTableList = dicList;
            return View();
        }
    }
}
